/**
 * Copyright (C) 2010, 2011 by Marco Tupiza.
 *
 * Project Info: http://sourceforge.net/projects/aplilibrary/
 *
 * * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. in the
 * United States and other countries.]
 *
 * --------- Aplinfo Library --------- (C) Copyright 2010-2011, by Aplinfo -
 * Marco V. Tupiza A.
 *
 * Original Author: Marco Tupiza (Aplinfo) Contributor(s): Marcia Conlago
 *
 */
package org.apli.jsf.converter;

import com.apli.controladores.AplinfoFactoryBean;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.faces.convert.Converter;
import org.apli.haiam.ejb.interfaces.AdministradorHaiam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Clase base JsfConverterBean que implementa los métodos genéricos para un
 * converter en JSF. 
 *
 * <H6>Soporte:HAIAM
 * <I>david_s_1086@hotmail.com,david.carranza@haiam.gob.ec</I></H6>
 *
 * @author david Carranza
 * @version 1.0 30/07/2014
 */
public abstract class JsfConverterBean implements Converter {

    final Logger log = LoggerFactory.getLogger(JsfConverterBean.class);

    protected abstract ResourceBundle getProperties();
    @EJB
    protected AdministradorHaiam admin;

    /**
     * Constructor.
     */
    public JsfConverterBean() {
        cargarEjb();
    }

    /**
     * Obtiene el objeto remoto.
     */
    protected void cargarEjb() {
        String nombreMetodo = Thread.currentThread().getStackTrace()[1].getMethodName() + "()";
        if (admin == null) {
            String ejbPath = null;
            try {
                ResourceBundle property = getProperties();
                String ORBContext = property.getString("ORBContext");
                String ejbContextPath = property.getString("ejb.context.path.admin");
                ejbPath = ORBContext + ejbContextPath + "/AdministradorBeanHaiam";
                admin = (AdministradorHaiam) AplinfoFactoryBean.lookupBean(ejbPath, false);
            } catch (Exception e) {
                log.error("{}: {} - {} ", new Object[]{nombreMetodo, ejbPath, e});
            }
        }
    }
}
